package beautiful.butterfly.drds.data_exchange.taskgroup.runner;


import beautiful.butterfly.drds.data_exchange.constant.State;
import beautiful.butterfly.drds.data_exchange.error_code.DataExchangeException;
import beautiful.butterfly.drds.data_exchange.error_code.FrameworkErrorCode;
import beautiful.butterfly.drds.data_exchange.taskgroup.TaskGroupContainer;
import lombok.Getter;
import lombok.Setter;

public class TaskGroupContainerTask implements Runnable
{
    @Setter
    @Getter
    private TaskGroupContainer taskGroupContainer;
    @Setter
    @Getter
    private State state;

    public TaskGroupContainerTask(TaskGroupContainer taskGroupContainer)
    {
        this.taskGroupContainer = taskGroupContainer;
        this.state = State.succeeded;
    }


    public void run()
    {
        try
        {
            this.taskGroupContainer.run();
            this.state = State.succeeded;
        } catch (Throwable e)
        {
            this.state = State.failed;
            throw DataExchangeException.asDataExchangeException(
                    FrameworkErrorCode.RUNTIME_ERROR, e);
        }
    }


}
